package com.flong.juc.charter1;

/**
 * @Author:liangjl
 * @Date: 2020/7/4-21:45
 * @Eamil:jilongliang@sina.com
 * @Description:
 * yield 方法的作用是放弃当前CPU资源，将资源让给其他的任务占用CPU其他，但放弃时间不确定，有可能刚刚放弃，马上
 * 又获取CPU时间片,减少线程时间
 */
public class MyTest10 {
    public static void main(String[] args) {
        Thread t = new MyTest10Thread();
        t.start();
    }


}

class MyTest10Thread extends Thread {
    @Override
    public void run() {
        int count = 0;
        long start = System.currentTimeMillis();
        for (int i = 0; i <= 500000; i++) {
            Thread.yield();
            count += i + 1;
        }
        long end = System.currentTimeMillis();

        System.out.println("用时：" + (end - start) + "毫秒");
    }

}
